package com.gujia.concurrency.example.singleton;

import com.gujia.concurrency.annoations.Recommend;
import com.gujia.concurrency.annoations.ThreadSafe;

/**
枚举模式--最安全
 */
@ThreadSafe
@Recommend
public class SingletonExample7 {


    private SingletonExample7(){

    }

    public static SingletonExample7 getInnstance(){

        return Singleton.INSTANCE.getInnstance();
    }


    private enum Singleton{
        INSTANCE;

        private SingletonExample7 singleton;
        //jvm保证这个方法绝对只调用一次
        Singleton(){
            singleton = new SingletonExample7();
        }

        public SingletonExample7 getInnstance() {
            return singleton;
        }
    }
}
